/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public boolean isCompleteTree(TreeNode root) {
        Queue <TreeNode> queue=new LinkedList<>();
        boolean reach=false;
        queue.offer(root);
        while(!queue.isEmpty()){
            TreeNode res=queue.poll();
            if(reach&&res!=null){
                return false;
            }
            if(res==null){
                reach=true;
                continue;
            }
            queue.offer(res.left);
            queue.offer(res.right);
        }
        return true;

    }
}
